﻿using System;

namespace ForgeCraft
{
    public class CmdPlayers : Command
    {
        public override string name { get { return "players"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "general"; } }
        public override bool consoleUsable { get { return false; } }
        public override Permission defaultRank { get { return Permission.Guest; } }
        public CmdPlayers() { }

        public override void Use(Player p, string message)
        {
            Player[] players = Server.playerList;
            if (players.Length > 0)
            {
                string playerListString = "There " + (players.Length == 1 ? "is 1 player" : "are " + players.Length + " players") + " on the server: ";
                bool first = true;
                foreach (Player pl in players)
                {
                    if (!first) playerListString += ", ";
                    playerListString += pl.info.group.color + p.nick;
                    first = false;
                }
                p.Message(playerListString);
            }
            else
            {
                p.Message("There appear to be no players on the server.");
            }
        }
        public override void Help(Player p)
        {
            p.Message(Color.Aqua + "/players " + Color.Help + "- Lists all players on the server.");
        }
    }
}